package com.gec.oasys.controller;

import com.gec.oasys.pojo.SysDepartMent;
import com.gec.oasys.service.SysDepartMentService;
import com.gec.oasys.util.SoulPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SysDepartMentController {
    @Autowired
    private SysDepartMentService sysDepartMentService;
    @RequestMapping("/findSysDepartMentById")
    @ResponseBody
    public Map<String, Object> findSysDepartMentById(Integer id){
        HashMap<String, Object> mapData = new HashMap<>();
        String code="1",msg="内部错误";
        SysDepartMent sysDepartMent=sysDepartMentService.selectByPrimaryKey(id);
        code="0";msg="成功";
        mapData.put("code",code);
        mapData.put("msg",msg);
        mapData.put("data",sysDepartMent);
        return mapData;
    }
    @RequestMapping("/toSysDepartMentList")
    public String toSysDepartMentList(){
        return "sys/sysdepartmentlist";
    }
    /*@RequestMapping("/getDataBySysDepartment2")
    @ResponseBody
    public Map<String,Object> getDataBySysDepartment(SysDepartMent sysDepartMent) {
        HashMap<String, Object> mapData = new HashMap<>();
        String code="1",msg="内部错误";
        List<SysDepartMent> sysDepartMentList= sysDepartMentService.querSysDepartment(sysDepartMent);
        code="0";msg="成功";
        mapData.put("code",code);
        mapData.put("msg",msg);
        mapData.put("count",sysDepartMentList.size());
        mapData.put("data",sysDepartMentList);
        return mapData;
    }*/
    @RequestMapping("/deleteSysDepartMentById")
    @ResponseBody
    public Map<String,Object> deleteSysDepartMentById(Integer id){
        HashMap<String, Object> mapData = new HashMap<>();
        String code="1",msg="内部错误";
        int pos =sysDepartMentService.deleteByPrimaryKey(id);
        if(pos>0){
            code="0";msg="成功";
        }
        mapData.put("msg",msg);
        mapData.put("code",code);
        return mapData;
    }
    @RequestMapping("/deleteSysDepartMentsById")
    @ResponseBody
    public Map<String,Object> deleteSysDepartMentsById(String ids){
        HashMap<String, Object> mapData = new HashMap<>();
        String code="1",msg="内部错误";
        String strids[]=ids.split(",");
        int pos =sysDepartMentService.deletesByPrimaryKey(strids);
        if(pos>0){
            code="0";msg="成功";
        }
        mapData.put("msg",msg);
        mapData.put("code",code);
        return mapData;
    }
    @RequestMapping("/toSysDepartMentAdd")
    public String toSysDepartMentAdd(){
        return "sys/sysdepartmentadd";
    }
    @RequestMapping("/getSysDepartMentTreeDataById")
    @ResponseBody
    public List<SysDepartMent> getSysDepartMentTreeDataById(Integer id){
        return sysDepartMentService.getSysDepartMentTreeDateById(id);
    }
    @RequestMapping("/saveSysDepartMent")
    @ResponseBody
    public Map<String,Object> saveSysDepartMent(SysDepartMent sysDepartMent){
        Map<String,Object> mapData=new HashMap<>();
        String code="1",msg="内部错误";
        int pos=sysDepartMentService.insert(sysDepartMent);
        if(pos>0){
            code="0";msg="成功";
        }
        mapData.put("msg",msg);
        mapData.put("code",code);
        return mapData;
    }
    @RequestMapping("/updateBySysDepartMentPrimaryKey")
    @ResponseBody
    public Map<String,Object> updateByPrimaryKey(SysDepartMent sysDepartMent){
        Map<String,Object> mapData=new HashMap<>();
        String code="1",msg="内部错误";
        int pos=sysDepartMentService.updateByPrimaryKey(sysDepartMent);
        if(pos>0){
            code="0";msg="成功";
        }
        mapData.put("msg",msg);
        mapData.put("code",code);
        return mapData;
    }
    @RequestMapping("/getDataBySysDepartment")
    @ResponseBody
    public Object dataGrid(SoulPage<SysDepartMent> soulPage, SysDepartMent sysDepartMent) {
        soulPage.setObj(sysDepartMent);
        return sysDepartMentService.dataGrid(soulPage);
    }
}
